package com.jxgm.spring.boot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * @author Administrator
 * @date 2020/10/14 8:22
 * @description
 **/
@Controller
public class LoginController {

    @RequestMapping(value = "/user/to/login")
    public String toLogin(){
        return "login";
    }

    @RequestMapping(value = "/user/do/login")
    public String login(
            @RequestParam("username") String username,
            @RequestParam("password") String password,
            HttpSession session,
            ModelMap modelMap){

        if ("jack".equals(username)&&"123456".equals(password)){
            session.setAttribute("username",username);
            return "redirect:/user/main";
        }else {

            modelMap.addAttribute("msg", "登录失败，用户名或密码错误！");

            return "login";
        }

    }

}
